#!/bin/sh
# - delay
# - duration
# - gap

# NOTE: this monitor is aimed for capturing all hot code as testcase runs
# with the minimum effort of storing and then parsing huge data file. And
# it's for debug purpose.
#
# Some idea and code are borrowed from monitor/no-stdout/perf-profile

. $LKP_SRC/lib/env.sh
. $LKP_SRC/lib/debug.sh
. $LKP_SRC/lib/wait.sh

: "${delay:=0}"
: "${duration:=10}"
: "${gap:=10}"

set_perf_path "/lkp/benchmarks/perf/perf"

setup_wait
wait_timeout $delay

$perf -v || die 'perf command failed'
while true; do
	$perf record -g -a -q -o perf.record -- timeout $duration $WAIT_POST_TEST_CMD

	date "+%F %T"
	$perf report -i perf.record --stdio 2>/dev/null | head -n 1000
	wait_timeout $interval
done
